package com.cskaoyan.market.aspect;



import com.cskaoyan.market.service.WxCartService;
import com.cskaoyan.market.util.ResponseUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
@Aspect
public class WxCartAspect {
    @Autowired
    WxCartService wxCartService;

    @Pointcut("@annotation(com.cskaoyan.market.annotation.WxCartAnnotation)")
    public void pt(){}

    @Around("pt()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint)throws Throwable{
        HashMap<String, Object> data = (HashMap<String, Object>)joinPoint.proceed();
        //增强,影响返回结果
        HashMap<String, Object> cartTotal = new HashMap<>();
        cartTotal.put("checkedGoodsAmount",wxCartService.checkedGoodsAmount());
        cartTotal.put("checkedGoodsCount",wxCartService.checkedGoodsCount());
        cartTotal.put("goodsAmount",wxCartService.goodsAmount());
        cartTotal.put("goodsCount",wxCartService.goodsCount());

        data.put("cartTotal",cartTotal);
        Object ok = ResponseUtil.ok(data);
        return ok;
    }

}